<?php

/**
 # com_jvframwork - JV Framework
 # @version		1.5.x
 # ------------------------------------------------------------------------
 # author    Open Source Code Solutions Co
 # copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved.
 # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later.
 # Websites: http://www.joomlavi.com
 # Technical Support:  http://www.joomlavi.com/my-tickets.html
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');

class JVParams extends JObject {
	
	protected $params;  
    protected $activeTheme;  
    
    /**
     * constructor method
     */
    public function __construct($paramsdata,$activeTheme) {
    	$this->params      = new JVParameter($paramsdata);
        $this->activeTheme = $activeTheme;
    }
    
    public function def($key, $default = '', $group = '_default'){
        $value = $this->params->get($key, (string) $default, $group);
		return $this->params->set($key, $value);
    }
    
    public function set($key, $value = '', $group = '_default'){
        return $this->params->setValue($group.'.'.$key, (string) $value);
    }
    
    /**
     *  getInstance
     */
    public function &getInstance($paramsdata,$activeTheme) {
        static $instance = null;
        if (!isset($instance)) {
            $instance = new JVParam($paramsdata,$activeTheme);
        }
        return $instance;
    }  
    /**
     * Parameter
     * @param parameter, default value
     * @return parameter value
     */
    public function getParam($param, $default = '') {
        return $this->params->get($param, $default);
    }

    /**
     * Get logo
     * @type Backend
     * @param parameter logotype
     * @return string logotype 'image' for image logo, 'text' for text logo
     */
    public function getLogo() {

        if ($this->getParam('logotype','logo') == 'text') {
            $logo = "<div id='logotext'><a href='".JURI::base()."' title='" . $this->getLogoText() . "'>" . $this->getLogoText() . "</a></div>";
            $logo .= "<div class='slogan'>" . $this->getSlogan() . "</div>";
            return $logo;
        } else {
            $logo = "<div id='logo'><a href='".JURI::base()."' title='" . $this->getLogoText() . "'></a></div>";            
        }



        return $logo;
    }

    /**
     * Get logo position
     * @type Backend
     * @param parameter logoposition
     * @return string position
     */
    public function getLogoPosition() {
        return $this->getParam('logoposition', 'logo');
    }

    /**
     * Get logo text
     * @type Backend
     * @param parameter logotext
     * @return string logotext
     */
    public function getLogoText() {
        return $this->getParam('logotype-text', 'JV FRAMEWORK');
    }

    /**
     * Get slogan
     * @type Backend
     * @param parameter slogan
     * @return string slogan
     */
    public function getSlogan() {
        return $this->getParam('logotype-slogan', 'Your slogan');
    }

    /**
     * Get logo image
     * @type Backend
     * @param parameter logoimage
     * @return string image link
     */
    public function getLogoImage() {
        return $this->getParam('logotype-image', -1);
    }

    /**
     * Templatewidth
     * @type Backend
     * @param parameter templatewidth
     * @return int the width of the template
     */
    public function getTemplateWidth() {
        return $this->getParam('templatewidth', 960);
    }

    /**
     * Main width
     * @type Backend
     * @param param
     * @return int Main width
     */
    public function getMainWidth() {
        $main = $this->getMainBodyWidth();
        return $main;
    }

    /**
     * MainBody Width
     * @type Backend
     * @param param
     * @return int Containtner width
     */
    public function getMainBodyWidth() {
        $contentner = $this->getTemplateWidth();
        return $contentner;
    }

    /**
     * Left width
     * @type Backend
     * @param parameter leftwidth
     * @return int left width
     */
    public function getSidebarWidth($sidebar) {
        return $this->getParam($sidebar, 300);

    }

    /**
     * Get spacewidth
     * @type Backend
     * @param parameter spacewidth
     * @return int space width
     */
    public function getSpaceWidth() {
        return $this->getParam('spacewidth', 10);
    }

    /**
     * Get global fontSize
     * @type Backend
     * @param parameter fontsize
     * @return string fontsize
     */
    public function getFontSize() {
        return $this->getParam('fontsize', 12);
    }
    
    /**
     * Get fontfamily
     * @type Backend
     * @param parameter fontfamily
     * @return string fontfamily
     */
    public function getFontFamily() {
        $font = array();
        
        $font[0]='';
        $font[1]='Arial, Helvetica, sans-serif';
        $font[2]='"Arial Black", Gadget, sans-serif';
        $font[3]='Tahoma, Geneva, sans-serif';
        $font[4]='Verdana, Geneva, sans-serif';
        $font[5]='"Courier New", Courier, monospace';
        $font[6]='"Times New Roman", Times, seri';
        $font[7]='Georgia, "Times New Roman", Times, serif';
        $font[8]='"Trebuchet MS", Arial, Helvetica, sans-serif';        
        $font[9]='"Palatino Linotype", "Book Antiqua", Palatino, serif';
        $font[10]='"Lucida Sans Unicode", "Lucida Grande", sans-serif';
        $font[11]='"MS Serif", "New York", serif';
        $font[12]='"Lucida Console", Monaco, monospace';
        $font[13]='"Comic Sans MS", cursive';
       
        return $font[(int)$this->getParam('fontfamily', '0')];
    }

    /**
     * Google Font API
     * @type Backend
     * @param parameter gfont
     * @return array google font
     */
    public function getGfont() {
        $font = array();        
        $font['gfontbody'] = $this->getParam('gfontbody', '');
        $font['gfontlogo'] = $this->getParam('gfontlogo', '');
        $font['gfontslogan'] = $this->getParam('gfontslogan', '');
        $font['gfontmainmenu'] = $this->getParam('gfontmainmenu', '');
        $font['gfontsubmenu'] = $this->getParam('gfontsubmenu', '');
        $font['gfontcontentheading'] = $this->getParam('gfontcontentheading', '');
        $font['gfontcomponent'] = $this->getParam('gfontcomponent', '');
        $font['gfontpageheading'] = $this->getParam('gfontpageheading', '');
        $font['gfontmoduletitle'] = $this->getParam('gfontmoduletitle', '');
        
        return $font;
    }

    /**
     * Change Layout
     * @type Backend
     * @param param 'layout'
     * @return string layout
     */
    public function getLayout() {        
        return $this->getParam('layout', 'default');
    }
    
    /**
     * Layout Override Directory
     * @type Backend
     * @param param 'layoutoverridedir'
     * @return string layout dir
     */
    public function layoutOverrideDir() {
        return $this->getParam('layoutoverridedir', 'default');
    }


    /**
     * Layout Setting
     * @type Backend
     * @param param 'layoutsetting'
     * @return string layout setting
     */
    public function getLayoutSetting() {
        if ($this->getParam('layoutsetting', '') == '') {
            return;
        }
        return $this->getParam('layoutsetting', '');
    }

    /**
     * Layout Type
     * @type Backend
     * @param param 'layouttype'
     * @return string layouttype
     */
    public function getLayoutType() {
        if (isset($_COOKIE['jvtheme'.$this->activeTheme->id]['layouttype'])) {
            return  $_COOKIE['jvtheme'.$this->activeTheme->id]['layouttype'];
        }  
              
        $layout_type = $this->getParam('layouttype', 'left-main-right');        
        if($this->getParam('layouttype', 'left-main-right') == 'default'){
            $layout_type = 'left-main-right';
        }        
        return $layout_type;
    }

    /**
     * Change template color
     * @type Backend
     * @param parameter templatecolor
     * @return string color
     */
    public function getTemplateColor() {
        if (isset($_COOKIE['jvtheme'.$this->activeTheme->id]['templatecolor'])) {
            return  $_COOKIE['jvtheme'.$this->activeTheme->id]['templatecolor'];
        }
        $files = JFolder::files(JPATH_ROOT.DS.'templates'.DS.'jv-framework'.DS.'themes'.DS.$this->activeTheme->theme.DS.'css'.DS.'colors'.DS,'css');
        $val	= isset($files[0]) ? str_replace('.css','',$files[0]) : '';
        
        return $this->getParam('templatecolor', $val);
    }

    /**
     * Change template hover color
     * @type Backend
     * @param parameter templatehovercolor
     * @return string color
     */
    public function getTemplateHoverColor() {
        return $this->getParam('templatehovercolor', '');
    }

    /**
     * Change link color
     * @type Backend
     * @param parameter linkcolor
     * @return string color
     */
    public function getLinkColor() {
        return $this->getParam('linkcolor', '');
    }

    /**
     * getDirection
     * @type Backend
     * @param parameter 'direction'
     * @return string direction 'rtl' for right to left direction or 'ltr' for left to right direction
     */
    public function getDirection() {
        $document = JVFactory::getFramework();
        if(isset($_COOKIE['jvtheme'.$this->activeTheme->id]['direction'])){
            return  $_COOKIE['jvtheme'.$this->activeTheme->id]['direction'];    
        }            
       
        return $this->getParam('direction', 'ltr');
    }

    /**
     * Footer Seo Script
     * @type Backend
     * @param parameter 'footerscript'
     * @return string footerscript
     */
    public function getFooterScript() {
        return $this->getParam('footerscript', '');
    }

    /**
     * Enable Copyright
     * @type Backend
     * @param parameter 'enablecopyright'
     * @return bool true if copyright is enable or false if it is not.
     */
    public function enableCopyright() {
        return $this->getParam('enablecopyright', 1);
    }
    
    /**
     * Enable Copyright
     * @type Backend
     * @param parameter 'enablecopyright'
     * @return bool true if copyright is enable or false if it is not.
     */
    public function enableFwCopyright() {
        return $this->getParam('enablefwcopyright', '');
    }

    /**
     * Framework Copyright
     * @type Backend
     * @param parameter 'footercopyright'
     * @return string Copyright
     */
    public function getCopyright() {
        return $this->getParam('footercopyright', '');
    }

    /**
     * Joomla Copyright
     * @type Backend
     * @param parameter 'joomlacopyright'
     * @return string Joomla Copyright
     */
    public function getJoomlaCopyright() {
        return $this->getParam('joomlacopyright', '');
    }

    /**
     * Enable JVSEO
     * @type Backend
     * @param parameter 'enableseokey'
     * @return bool true if enabled and false if it is not.
     */
    public function enableSeokey() {
        if ($this->getParam('enableseokey', '0') == '1') {
            return true;
        }
        return false;
    }
    /**
     * JVSEO
     * @type Backend
     * @param parameter 'jvkeyseo'
     * @return array Key=>Link
     */
    public function getSeoKey() {
        $seokey = $this->getParam('jvkeyseo', '');
        $seokey = explode("\n", $seokey);
        return $seokey;
    }
    
    /**
     * Enable Usertool
     * 
     * @type Backend
     * @param parameter 'enableusertool'
     * @return bool true if usertool is enabled and false otherwise.
     */
    public function enableUsertool() {
        if ($this->getParam('enableusertool', '') == '1') {
            return true;
        }
        return false;
    }
    
    /**
     * Compress css,js
     * @type Backend
     * @param parameter 'css_compress|js_compress|gzip_compress'
     * @return array boolean	The first array element is css compression, the second is js compression and the third is gzip compression.
	 * 							If one array element value is true the correspond compression method is enabled and otherwise.
     */
    public function getCompress() {
        $array = array('css_compress' => $this->getParam('css_compress', '0'), 'js_compress' => $this->getParam('js_compress', '0'),
            'gzip_compress' => $this->getParam('gzip_compress', '0'));

        return $array;
    }

    /**
     * enableJVMenu
     * @type Backend     
     * @return bool true if JVMenu is enabled else return false. 
     */
    public function enableJVMenu() {
        return $this->getParam('menuapplyto', '') != '';
    }

    /**
     * enableVerticalMenu
     * @type Backend     
     * @return bool true if Vertical Menu is enabled else return false.
     */
    public function enableVerticalMenu() {
        return $this->getParam('vmenuapplyto', '') != '';
    }

    /**
     * enableAccordionMenu
     * @type Backend     
     * @return bool true if AccordionMenu is enabled else return false.
     */
    public function enableAccordionMenu() {
        return $this->getParam('amenuapplyto', '') != '';
    }
    
    /**
     * Theme assign
     * 
     * @type Backend     
     * @return array menu items id.
     */
    public function themeAssign() {        
        jimport('joomla.filesystem.folder');
        jimport('joomla.filesystem.file');
        
        $path = JPATH_ROOT . DS . 'templates' . DS . JVLayout::getTemplate() . DS . 'themes';
        $themeAsign = array();

        $folders = JFolder::folders($path);
        
        foreach($folders as $folders){
            $theme = (array) $this->getParam('theme'.$folders, '');
            
            if(is_array($theme)){
                foreach($theme as $menuItems){
                    $themeAsign[$menuItems] = $folders;
                }
                
            }
        }
        
        if(count($themeAsign)){
            return $themeAsign;
        }
        return;
    }
    
    /**
     * Menu Style
     * @type Backend     
     * @return string menu type
     */
    public function getMenuStyle() {
        if (isset($_COOKIE['jvtheme'.$this->activeTheme->id]['menustyle'])) {
            return  $_COOKIE['jvtheme'.$this->activeTheme->id]['menustyle'];
        } 
        return $this->getParam('menustyle', 'css');
    }
    
    /**
     * Menu fx mode
     * @type Backend     
     * @return string fx mode
     */
    public function getMenuFxMode() {
        if (isset($_COOKIE['jvtheme'.$this->activeTheme->id]['menufxmode'])) {
            return  $_COOKIE['jvtheme'.$this->activeTheme->id]['menufxmode'];
        }
        return $this->getParam('menufxmode', 'heightopacity');
    }
    
    /**
     * Apply menu to
     * @type Backend     
     * @return string class to apply the menu
     */
    public function getMenuApplyTo() {
        return $this->getParam('menuapplyto', '-1');
    }
    
    /**
     * Menu fx duration 
     * @type Backend     
     * @return int duration time
     */
    public function getMenuFxDuration() {
        return $this->getParam('menufxduration', 350);
    }
    
    /**
     * Menu fx transition
     * @type Backend     
     * @return string transition effect
     */
    public function getMenuFxTransition() {
        return $this->getParam('menufxtransition', 'linear');
    }
    
    
    /**
     * Menu fx ease
     * @type Backend     
     * @return string ease effect
     */
    public function getMenuFxEase() {
        return $this->getParam('menufxease', 'easeIn');
    }
    
    /**
     * Menu fx showdelay
     * 
     * @type Backend     
     * @return int delay time
     */
    public function getFxShowDelay() {
        return $this->getParam('menufxshowdelay', 250);
    }
    
    /**
     * Menu fx hidedelay
     * 
     * @type Backend     
     * @return int delay time
     */
    public function getMenuFxHideDelay() {
        return $this->getParam('menufxhidedelay', 250);
    }
    /**
     * Menu click to open
     * 
     * @type Backend     
     * @return bool 
     */
    public function getMenuClickToOpen() {
        return $this->getParam('menuclicktoopen', 0);
    }
    
    /**
     * VMenu Style
     * @type Backend     
     * @return string menu type
     */
    public function getVMenuStyle() {
        return $this->getParam('vmenustyle', 'face');
    }
    
    /**
     * Menu fx mode
     * @type Backend     
     * @return string fx mode
     */
    public function getVMenuFxMode() {
        return $this->getParam('vmenufxmode', 'widthopacity');
    }
    
    /**
     * Apply menu to
     * @type Backend     
     * @return string class to apply
     */
    public function getVMenuApplyTo() {
        return $this->getParam('vmenuapplyto', '-1');
    }
    
    /**
     * Menu fx duration 
     * @type Backend     
     * @return int duration time
     */
    public function getVMenuFxDuration() {
        return $this->getParam('vmenufxduration', 350);
    }
    
    /**
     * Menu fx transition
     * @type Backend     
     * @return string transition effect
     */
    public function getVMenuFxTransition() {
        return $this->getParam('vmenufxtransition', 'linear');
    }
    
    
    /**
     * Menu fx ease
     * @type Backend     
     * @return string ease effect
     */
    public function getVMenuFxEase() {
        return $this->getParam('vmenufxease', 'easeIn');
    }
    
    /**
     * Menu fx showdelay
     * 
     * @type Backend     
     * @return int delay time
     */
    public function getVFxShowDelay() {
        return $this->getParam('vmenufxshowdelay', 250);
    }
    
    /**
     * Menu fx hidedelay
     * 
     * @type Backend     
     * @return int delay time
     */
    public function getVMenuFxHideDelay() {
        return $this->getParam('vmenufxhidedelay', 250);
    }
    /**
     * Menu click to open
     * 
     * @type Backend     
     * @return bool 
     */
    public function getVMenuClickToOpen() {
        return $this->getParam('vmenuclicktoopen', 0);
    }
        
    /**
     * Menu fx mode
     * @type Backend     
     * @return string fx mode
     */
    public function getAMenuFxMode() {
        return $this->getParam('amenufxmode', '');
    }
    
    /**
     * Apply menu to
     * @type Backend     
     * @return string class to apply
     */
    public function getAMenuApplyTo() {
        return $this->getParam('amenuapplyto', '-1');
    }
    
    /**
     * Menu fx duration 
     * @type Backend     
     * @return int duration time
     */
    public function getAMenuFxDuration() {
        return $this->getParam('amenufxduration', 350);
    }
    
    /**
     * Menu fx transition
     * @type Backend     
     * @return string transition effect
     */
    public function getAMenuFxTransition() {
        return $this->getParam('amenufxtransition', 'linear');
    }
    
    
    /**
     * Menu fx ease
     * @type Backend     
     * @return string ease effect
     */
    public function getAMenuFxEase() {
        return $this->getParam('amenufxease', 'easeIn');
    }    
    
    /**
     * Menu click to open
     * 
     * @type Backend     
     * @return bool true if Click To Open feature is enabled else return false
     */
    public function getAMenuClickToOpen() {
        return $this->getParam('amenuclicktoopen', 1);
    }
    
    /**
     * Menu always hide
     * 
     * @type Backend     
     * @return bool true if always hide is enable else return false
     */
    public function getAMenuAlwaysHide() {
        return $this->getParam('amenualwayshide', 0);
    }
     
    
    /**
     * enableLazyLoad
     * @type Backend     
     * @return bool true if LazyLoad is enabled else return false. 
     */
    public function enableLazyLoad() {
        return $this->getParam('lazyload', 0);
    }    
	
	    
    /**
     * lazyLoadSelector
     * @type Backend     
     * @return bool true if LazyLoad is enabled else return false. 
     */
    public function lazyLoadSelector() {
        return $this->getParam('jvlazyloadselector', '#maincontent img');
    }  
	
	/**
     * lazyLoadSelector
     * @type Backend     
     * @return bool true if LazyLoad is enabled else return false. 
     */
    public function enableBackToTop() {
        return $this->getParam('enablebacktotop', 1);
    }
    
    /**
     * enableLazyLoad
     * @type Backend     
     * @return bool true if LazyLoad is enabled else return false. 
     */
    public function enableMobileLayout() {
        return $this->getParam('enablemobilelayout', 1);
    }     
}
